home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_8.zip
/
CWKTASK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-29
|
20KB
|
733 lines
/*
GWMON Parallel Ada Monitor for 386/486 PCs
Copyright (C) 1993, Charles W. Kann & Michael Bliss Feldman
ckann@seas.gwu.edu mfeldman@seas.gwu.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ed.h"
#include "keydef.h"
/*
I need the variable "exception_trace" from ivars.h. I don't want
to use the whole .h, so I am including this one variable here.
*/
extern int exception_trace;
static int current_task;
static int save_block_number = -1;
static long Run_Current_Time; /* Run time (lines) since last report */
extern rr_flag;
void CWK_SET_TASK();
void CWK_SET_TASK_LINE();
void CWK_GET_KEY();
static void scroll_tasks();
void busy_wait(wait_cnt)
int wait_cnt;
{
int i, cycles;
cycles = delay_scaling_factor * delay_array[wait_cnt];
for ( i = 0; i < cycles; ++i );
}
void CWK_CREATE_TASK(task_no, task_name, task_file)
int task_no;
char *task_name;
char *task_file;
{
char msg[100];
int ch;
if ( task_no > MAX_TSKS ) {
printf("Can't work with more than %d tasks...", MAX_TSKS-1);
}
/*
Find the task particulars in the task file (For now, hard code them)
*/
CWK_TASKS[task_no].TN = malloc( strlen(task_name)+1 );
strcpy( CWK_TASKS[task_no].TN, task_name );
CWK_TASKS[task_no].FL = 1;
CWK_TASKS[task_no].LL = 10000;
CWK_TASKS[task_no].FLOS = 0;
CWK_TASKS[task_no].CL = 0;
CWK_TASKS[task_no].MON = CWK_CREATE_MON_WIN(CWK_TASKS[task_no].TN,
(monitor_type == 1) ? 1 : 0 );
CWK_TASKS[task_no].FD = CWK_LOAD_FILE(task_file);
}
/*************************************************************************/
/* */
/* CWK_Switch_Block is used to make sure the correct program block */
/* (ie procedure, package, task, etc) is being used. When a program*/
/* block becomes current, we want to make sure that we then move to */
/* use that program block. Program blocks are entered and exited */
/* inta.c. We call this routine from there. */
/* */
/* parameters: */
/* block_number : the block number of this block */
/* block_name : the title of the block (ie proc name) */
/* block_file : file which contains this block */
/* enter_or_exit: Are we entering or exiting this block */
/* This is only used in procedure monitoring */
/* If this is 1 - exiting, 0 - entering */
/* */
/*************************************************************************/
CWK_Switch_Block( block_number, block_name, block_package, block_file,
enter_or_exit )
int block_number, enter_or_exit;
char *block_name, *block_package, *block_file;
{
FILE_REC_PTR Save_FD;
char package_routine[68];
/*
In the case of task monitoring, if the new procedure is in
a different source file from the one currently being used,
move to that source file.
*/
if ( task_monitor )
{
Save_FD = CWK_TASKS[current_task].FD;
CWK_TASKS[current_task].FD = CWK_LOAD_FILE(block_file);
if ( Save_FD != CWK_TASKS[current_task].FD )
CWK_TASKS[current_task].FLOS = 0;
}
/*
Procedure monitoring
*/
else
{
/*
The save_block_number remembers the block between
calls. The first time through, however, it must be set
*/
if ( save_block_number == -1 )
save_block_number = block_number;
/*
If this block hasn't been created, and we have a valid
block, create it. If the block is part of a package,
prepend the package name.
*/
if ( strcmp( block_package, "main" ) != 0 )
{
strcpy( package_routine, block_package );
strcat( package_routine, "." );
strcat( package_routine, block_name );
}
else
strcpy( package_routine, block_name );
if ( CWK_BLKS[block_number].MON == NULL )
CWK_CREATE_BLOCK(block_number, package_routine,
block_file );
/*
Only worry about monitor windows if the monitor is
running.
*/
if ( monitor_type != 1 )
return;
if ( monitor_window_type == 3 )
{
save_block_number = block_number;
CWK_DRAW_PROC_WIN( CWK_BLKS[block_number].MON,
enter_or_exit );
CWK_BLKS[save_block_number].FLOS = 0;
#if 0
CWK_SET_TASK_LINE( CWK_BLKS[block_number].CL, 0 );
#endif
/*
If the mode is to be in task step mode,
then wait for a key to be pressed to
move to the next step, otherwise, wait
a second to keep the screen from flashing.
*/
if ( task_step )
CWK_GET_KEY( 1 );
else
busy_wait( MAX_DELAY-1 );
}
else
save_block_number = block_number;
}
}
CWK_LEAVE_BLOCK( block_number )
int block_number;
{
if ( monitor_type != 1 )
return;
if ( ! task_monitor )
CWK_REMOVE_BLOCK( CWK_BLKS[block_number].MON);
}
/*************************************************************************/
/*************************************************************************/
void CWK_DISTROY_TASK(task_no)
int task_no;
{
CWK_TASKS[task_no].TN = "";
CWK_TASKS[task_no].FL = 0;
CWK_TASKS[task_no].LL = 0;
CWK_DEL_MON_WIN(CWK_TASKS[task_no].MON);
}
void CWK_CHANGE_TASK_STAT(task_no, stat, task_name, task_file )
int task_no;
char stat;
char *task_name, *task_file;
{
int FLOS;
FLOS = CWK_TASKS[task_no].FLOS;
if ( ! task_monitor )
return;
CWK_TASKS[task_no].ST = stat;
switch( stat ) {
case 'C' : /* Create a new task */
CWK_CREATE_TASK( task_no, task_name, task_file );
CWK_TASKS[task_no].ST = '*';
break;
case 'A' : /* Activate a task */
CWK_SET_TASK( task_no );
CWK_TASKS[task_no].ST = '*';
if ( ( task_step ) && ( CWK_TASKS[task_no].MON->WON == 1 ) )
CWK_GET_KEY( 1 );
break;
case 'S' : /* Change to a new task */
CWK_SET_TASK( task_no );
CWK_TASKS[task_no].ST = '*';
break;
case 'D' : /* Delaying task */
if ( monitor_type == 1 )
{
CWK_CUR_LINE( CWK_TASKS[task_no].MON,
CWK_TASKS[task_no].CL- FLOS, " D " );
if ( ( task_step ) &&
( CWK_TASKS[task_no].MON->WON == 1 ) )
CWK_GET_KEY( 1 );
}
break;
case 'R' : /* Waiting Rendezvous */
if ( monitor_type == 1 )
{
CWK_CUR_LINE( CWK_TASKS[task_no].MON,
CWK_TASKS[task_no].CL- FLOS, " R " );
if ( ( task_step ) &&
( CWK_TASKS[task_no].MON->WON == 1 ) )
CWK_GET_KEY( 1 );
}
break;
case 'M' : /* Rendezvous Met */
if ( monitor_type == 1 )
{
CWK_CUR_LINE( CWK_TASKS[task_no].MON,
CWK_TASKS[task_no].CL- FLOS, " M " );
if ( ( task_step ) &&
( CWK_TASKS[task_no].MON->WON == 1 ) )
CWK_GET_KEY( 1 );
}
break;
case 'E' : /* Rendezvous Met */
CWK_DISTROY_TASK( task_no );
break;
}
}
void CWK_SET_TASK_LINE( line_no, getkey_or_not )
int line_no, getkey_or_not;
{
int i;
int FLOS;
static text_string[50], format_string[50];
TASK_REC *temp_task;
int task_no;
if ( task_monitor )
{
task_no = current_task;
temp_task = CWK_TASKS;
}
else
{
task_no = save_block_number;
temp_task = CWK_BLKS;
}
if ( temp_task[task_no].FD->lines_in_file < line_no )
{
return;
}
if ( ( temp_task[task_no].MON->WON != 1 ) ||
( monitor_type != 1 ) )
{
return;
}
FLOS = temp_task[task_no].FLOS;
if ( FLOS != 0 )
CWK_CUR_LINE(temp_task[task_no].MON,
temp_task[task_no].CL - FLOS, " ");
if (( FLOS == 0 ) ||